// pages/article/articleList/articleList.js
import getIn from '../../../sdk/utils/getIn';
import {API_ARTICLE_LIST} from "../../../sdk/business/url";
import {showSuccess,showFail} from '../../../utils/util';
import {ARTICLE_DETAIL} from "../../../utils/url";
Component({
  /**
   * 组件的属性列表
   */
  properties: {
      // showList:{
      //   type: Boolean,
      //   value: false
      // }
  },

  /**
   * 组件的初始数据
   */
  data: {
      articleList: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
      show(id, cate_name){
        this.fetchData(id);
        this.setData({ cate_name })
      },
      fetchData(id) {
          const params = { cate_id: id };
          wx.showLoading()
          this.setData({ loading: true });
          global.request(API_ARTICLE_LIST, params, (code, res) => {
              if (code = 'SUCCESS') {
                  const articleList = getIn(res.data, ['list']);
                  this.setData({ articleList });
                  wx.hideLoading()
              } else if (code == 'FAIL') {
                  showFail(res.msg)
                  wx.hideLoading()
              }
          });
      },
      toDetail(e) {
          const id = getIn(e.currentTarget, ['id']);
          const queryString = `id=${id}&cate_name=${this.data.cate_name}`;
          global.navigateHelper.navigateTo({ pathname: ARTICLE_DETAIL, queryString });
      }
  }
})
